import java.util.HashMap;
import java.util.Map;

/**
 * 好数对的数目
 *
 * @USER: Administrator
 * @DATE: 2024/9/28 上午11:22
 * @VERSION: 1.0.0
 */
public class LC1512 {
    public static void main(String[] args) {

    }

    public int numIdenticalPairs(int[] nums) {
        int count = 0;
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        for (int key : map.keySet()) {
            count += map.get(key) * (map.get(key) - 1) / 2;
        }
        return count;
    }

}
